{% extends "admin/change_form.html" %}

{% block content %}
    {{ block.super }}
    <script type="text/javascript">
        (function($) {
            $(document).ready(function() {
                var $authorsInput =$('#id_authors');
                var $addAuthorBtn =$('<button type="button">Add Author</button>');
                var $deleteAuthorBtn =$('<button type="button">Delete Author</button>');

                $addAuthorBtn.click(function() {
                    var account = prompt("Enter the account:");
                    var name = prompt("Enter the name:");
                    var role = prompt("Enter the role:");
                    if (account && name && role) {
                        var authors = JSON.parse($authorsInput.val() || '[]');
                        authors.push({account: account, name: name, role: role});
                        $authorsInput.val(JSON.stringify(authors));
                    }
                });

                $deleteAuthorBtn.click(function() {
                    var authors = JSON.parse($authorsInput.val() || '[]');
                    authors.pop();
                    $authorsInput.val(JSON.stringify(authors));
                });

                $authorsInput.after($addAuthorBtn).after($deleteAuthorBtn);
            });
        })(django.jQuery);
    </script>
{% endblock %}
